//
//  YSCardImageItemView.m
//  Yueshi
//
//  Created by yueshi_tech on 15/7/17.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSCardImageItemView.h"

@interface YSCardImageItemView()
@property(strong,nonatomic) UIImageView *image;
@property(strong,nonatomic) UIImageView *iconImage;
@property(strong,nonatomic) UILabel *descLabel;
@property(strong,nonatomic) UILabel *subDescLabel;
@end

@implementation YSCardImageItemView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //商品图片
        UIImageView *image = [[UIImageView alloc]init];
        [self addSubview:image];
        self.image = image;
        
        //描述前的icon
        UIImageView *iconImage = [[UIImageView alloc]init];
        [self addSubview:iconImage];
        self.iconImage = iconImage;
        
        //描述
        UILabel *descLabel = [[UILabel alloc] init];
        descLabel.textColor = DescColor;
        descLabel.font = SYS_FONT(DescFont);
        [self addSubview:descLabel];
        self.descLabel = descLabel;
        
        //子描述
        UILabel *subDescLabel = [[UILabel alloc] init];
        subDescLabel.textColor = SubDescColor;
        subDescLabel.font = SYS_FONT(SubDescFont);
        [self addSubview:subDescLabel];
        self.subDescLabel = subDescLabel;
    }
    return self;
}


-(void)setCardImageFrame:(YSCardImageItemFrame *)cardImageFrame{
    _cardImageFrame = cardImageFrame;
    
     YSAdvert *advert =  cardImageFrame.advert;
     self.image.frame = cardImageFrame.imageFrame;
     [self.image setImageURLStr:advert.advertImg];
    
     if(!ISBLANK(advert.advertTitle)){
        [self.iconImage setImageURLStr:advert.advertIcon];
        [self.iconImage setContentMode:UIViewContentModeScaleToFill];
        self.iconImage.frame = cardImageFrame.iconImageFrame;
        
        [self.descLabel setText:advert.advertTitle];
        self.descLabel.frame = cardImageFrame.descFrame;
        
        [self.subDescLabel setText:advert.advertText];
        self.subDescLabel.frame = cardImageFrame.subDescFrame;
     }else if(!ISBLANK(advert.advertText)){
         [self.subDescLabel setText:advert.advertText];
         self.subDescLabel.frame = cardImageFrame.subDescFrame;
     }
    
    self.frame = cardImageFrame.frame;
}

@end
